package top.yxqz.servelt;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import java.util.Set;

/**
 * @author Mr.余
 * @date 2022/11/15
 * @package top.yxqz.servelt
 */
public class MyServletContainer implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
//                创建Servlet对象
        ServletDemo02 servletDemo2 = new ServletDemo02();

//        在应用上下文中添加Servlet 并得到Servlet的配置对象
        ServletRegistration.Dynamic registration = servletContext.addServlet("servletDemo2", servletDemo2);
//        注册Servlet的访问映射时机
        registration.setLoadOnStartup(1);
//        添加映射
        registration.addMapping("/demo2");
//        是否支持异步
        registration.setAsyncSupported(false);
    }
}
